package trans.graphics;
import java.io.File;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import util.gen.*;

public class CombineXYSeries {

	public static void main(String[] args){
		if (args.length == 0) Misc.printExit("\nEnter two full path names for serialized XYSeries[] objects generated by the AggregatePlots app to combine and plot them.");
		
		//load series
		File one = new File (args[0]);
		File two = new File (args[1]);
		XYSeries[] raw1 = (XYSeries[]) IO.fetchObject(one);
		XYSeries[] raw2 = (XYSeries[]) IO.fetchObject(two);
		
		
		
		//make collection
		XYSeriesCollection rawDataSet = new XYSeriesCollection(); 
		 
		for (int i=0; i< raw1.length; i++) rawDataSet.addSeries(raw1[i]); 
		for (int i=0; i< raw2.length; i++) rawDataSet.addSeries(raw2[i]); 

		
		JFreeChart rawChart = ChartFactory.createXYLineChart( 
				null, // chart title 
				null, // x axis label 
				null, // y axis label 
				rawDataSet, // data 
				PlotOrientation.VERTICAL, 
				false, // include legend 
				true, // tooltips 
				false // urls 
		); 
		XYPlot plot = (XYPlot) rawChart.getPlot(); 
		XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); 
		renderer.setShapesVisible(false);
		renderer.setLinesVisible(true);
		renderer.setShapesFilled(false);
		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setAutoRangeIncludesZero(false);
		
		NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
		//domainAxis.setLowerBound(-2500);
		//domainAxis.setUpperBound(2500);
		
		
		
		System.setProperty("java.awt.headless","true");
		
		try {
			File png = new File(one.getParentFile(), one.getName()+"_"+two.getName()+"960.png");
			ChartUtilities.saveChartAsPNG(png,rawChart, 1440,960);
			
			png = new File(one.getParentFile(), one.getName()+"_"+two.getName()+"480.png");
			ChartUtilities.saveChartAsPNG(png,rawChart, 1440,480);
			
			png = new File(one.getParentFile(), one.getName()+"_"+two.getName()+"240.png");
			ChartUtilities.saveChartAsPNG(png,rawChart, 1440,240);
			
		} catch (Exception e){
			e.printStackTrace();
		}
		

		
		
	}
	
	
}
